package com.cdbkj.cloud.pos;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.androidyang.library.common.utils.ToastUtils;
import com.androidyang.library.http.okhttp.bean.HttpResult;
import com.androidyang.library.http.okhttp.listener.HttpClientHandler;
import com.cdbkj.cloud.pos.bean.JsonResult;
import com.cdbkj.cloud.pos.utils.Tools;
import com.dawn.cloud.pos.drive.sdk.YBSdk;

import java.util.Map;

public class YBActivity extends AppCompatActivity implements View.OnClickListener, HttpClientHandler {

    protected Button testBtn;

    protected TextView testTv;

    private String hisTime;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.activity_yb);
        initView();
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.test_btn) {

            String content = YBSdk.readCardInfo("000000");
            testTv.setText("");
        }
    }

    private void initView() {
        testBtn = findViewById(R.id.test_btn);
        testBtn.setOnClickListener(YBActivity.this);
        testTv = findViewById(R.id.test_Tv);
    }


    @Override
    public void httpClientSuccess(Object o, HttpResult httpResult) {
        JsonResult json = (JsonResult) httpResult.getResult();
        if (json == null) {
            ToastUtils.showShort(this,"服务器处理异常");
            return;
        }
        if (!json.isSuccess()) {
            ToastUtils.showShort(this,json.getMsg());
            return;
        }
        if(((Map)json.getData()).get("hisTime")==null){
            ToastUtils.showShort(this,"his不能正常访问");
            return;
        }
        hisTime = ((Map)json.getData()).get("hisTime").toString();
        hisTime = hisTime.substring(0,10);
    }

    @Override
    public void httpClientError(Object o, HttpResult httpResult) {
        ToastUtils.showShort(this,"网络异常");
    }
}
